#include "NameGenerator.h"


NameGenerator::NameGenerator(void)
{
}


NameGenerator::~NameGenerator(void)
{
	delete[] mNames;
}

int NameGenerator::AcquireNameListFromFile()
{
	std::ifstream fin("BoxerNameList.txt");
	if(!fin.is_open())
	{
		return 0;
	}

	char temp[200];
	fin.getline(temp,sizeof temp);
	fin.getline(temp,sizeof temp);
	fin.getline(temp,sizeof temp);
	fin >> mNumNames;
	mNames=new char *[mNumNames];
	unsigned i=0;
	fin.getline(temp,sizeof temp);
	while(fin.getline(temp,sizeof temp))
	{
		int value=strlen(temp)+1;
		mNames[i]= new char[value];
		strcpy(mNames[i],temp);
		//strcat(names[i],"\0");
		i++;
	}
	fin.close();
	return 1;
	/*for(int j=0; j!=nNames; j++)
	{
		std::cout << names[j] << std::endl;
	}*/
}
char * NameGenerator::GetName()
{
	if(!AcquireNameListFromFile())
	{
		return nullptr;
	}
	return mNames[rand() % mNumNames];

}